﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.SessionState;
using PreguntaAlExperto.RulesLayer.Entities;
using PreguntaAlExperto.RulesLayer.Services;

namespace PreguntaAlExperto
{
    public class Autenticar
         : IHttpHandler, IRequiresSessionState
    {

        public bool IsReusable
        {
            get
            {
                return true;
            }
        }

        public void ProcessRequest(HttpContext context)
        {
            if (!string.IsNullOrEmpty(context.Request.QueryString["Key"]))
            {
                PublisherService _service = new PublisherService();
                Publisher _publisher = _service.AutenticatePublisher(context.Request.QueryString["Key"].ToString());

                context.Session.Add("UserID", _publisher.ID_Publisher);
                context.Session.Add("UserName", _publisher.Name);
                context.Session.Add("UserLevel", _publisher.Member);
                context.Session.Add("LoginName", _publisher.Username);
            }

            context.Response.Redirect("~/default.aspx");
        }

    }
}
